package cn.bytecollege.admin.controller;

import cn.bytecollege.admin.service.CategoryService;
import cn.bytecollege.admin.service.CuisineService;
import cn.bytecollege.common.entity.Cuisine;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "CuisineUpdateController",value = "/admin/cuisineUpdate")
public class CuisineUpdateController extends HttpServlet {
    private CuisineService cuisineService=null;
    private CategoryService categoryService = null;

    public CuisineUpdateController() {
        cuisineService=new CuisineService();
        categoryService = new CategoryService();
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String cuisineName=request.getParameter("cuisineName");
        String cuisinePrice=request.getParameter("cuisinePrice");
        String cuisinePhoto=request.getParameter("cuisinePhoto");

        String cuisineId=request.getParameter("cuisineId");
        String categoryId=request.getParameter("category");
        Cuisine cuisine=new Cuisine();
        cuisine.setCuisineName(cuisineName);
        cuisine.setCuisinePrice(Double.valueOf(cuisinePrice));
        cuisine.setCuisinePhoto(cuisinePhoto);
        cuisine.setCategoryId(Integer.valueOf(categoryId));
        cuisine.setCuisineId(Integer.valueOf(cuisineId));

        request.setAttribute("cuisine",cuisine);

        cuisineService.update(cuisine);


        response.sendRedirect(request.getContextPath()+"/admin/cuisineList");
    }
}
